﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;

public class Death_Reload : MonoBehaviour
{
    public GameObject game_over;

    private int count = 0;

    private void OnTriggerEnter2D(Collider2D collision)
    {
        if(collision.tag == "Player" && count < 1)
        {
            count++;

            StartCoroutine(Reload());
        }

        if(collision.tag == "Enemy")
        {
            Destroy(collision.gameObject);
        }

        if(collision.tag == "Box")
        {
            StartCoroutine(Reload());
        }
    }

    IEnumerator Reload()
    {
        game_over.SetActive(true);

        // wait 
        yield return new WaitForSeconds(0.3f);

        // Level Reload
        SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);
    }
}
